<?php 
require_once 'core/init.php';

/*if (Session::exists('home')) {
	echo "<p>" . Session::flash('home') . "</p>";
}*/

$user = new User();

if($user->isLoggedIn()) {
?>	
	<p>Hello <a href="profile.php?user=<?php echo escape($user->data()->username); ?>">Profile</a></p>	
	<ul>
		<li><a href="logout.php">Logout</a></li>
		<li><a href="update.php">Update</a></li>
		<li><a href="changepassword.php">Change password</a></li>
	</ul>
<?php
	if (!$user->hasPermission('admin')) {
		echo "You are administrator";
	}

}else {
?>
	<p><a href="login.php">Login</a> or <a href="register.php">register</a></p>
<?php
}

if (Session::exists('home')) {
	echo Session::flash('home',  'Home success');
}



// SELECTING DATA
/*$user = DB::getInstance()->query('SELECT * FROM users');

if (!$user->count()) {
	echo "No user";	
}else {

	
	foreach ($user->results() as $user ) {
			
			echo $user->username, '<br/>';
			echo $user->joined, '<br/>';
		}	

}*/

//INSERTING DATA
/*$user = DB::getInstance()->insert('users', array(
	'username' => 'Dale', 
	'name' => 'Dale De guzman',
	'password' => 'password', 
	'salt' => 'salt'));*/
/*

//UPDATING DATA
$user = DB::getInstance()->update('users', 5, array(

	'password' => 'sdasdasd',
	'name' => 'Dale ssss'
));*/



